Add cache level limits to AddCacheInfo#190
Closed
wamuir wants to merge 1 commit into
Closed
Conversation
Collaborator
|
Thx for the PR, I spotted it this morning as well. It's still not a proper fix but at least it will fix the corruption. |
Collaborator
|
Ha my bad I misread your patch. I'll send a fix ASAP |
Author
|
Awesome, thanks! |
Collaborator
|
The memory corruption is fixed but cache info might be duplicated (read from Leaf2 and Leaf 4/0x8000001D). |
EylonKrause
added a commit
to EylonKrause/cpu_features
that referenced
this pull request
Jun 30, 2026
…_LEVEL ParseLeaf2 appends a CacheLevelInfo to CacheInfo::levels (a fixed CPU_FEATURES_MAX_CACHE_LEVEL=10 array) for every non-zero leaf-2 descriptor byte, but the loop is bounded only by sizeof(data)==16 and never checks info->size against the array capacity. A CPUID leaf 2 advertising more than 10 non-zero descriptors (up to 15 are possible) writes past levels[10] -- an out-of-bounds write reachable from public GetX86CacheInfo() on hardware/hypervisor-controlled CPUID input. The sibling ParseCacheInfo already guards its loop with 'info.size < CPU_FEATURES_MAX_CACHE_LEVEL' (added for the same class of corruption in google#190); apply the same bound to ParseLeaf2. Adds a regression test (Leaf2_TooManyDescriptors_DoesNotOverflow) that feeds a leaf 2 with 15 descriptors: it triggers an ASan stack-buffer-overflow before the fix and passes after.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
list_cpu_featuressegfaults in at least some cases after 641e24e. I am experiencing on Linux (Comet Lake) and FreeBSD (Kaby Lake). PR resolves by limiting parsing in AddCacheInfo to the range of possible cache levels.